package net.lookyou.boot.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lookyou.boot.demo.entity.User;
import net.lookyou.boot.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public User getOne(int id)
    {
        return userMapper.selectById(id);
    }

    public User userDetail(User user){
        QueryWrapper<User> wrapper = new QueryWrapper<User>();

        wrapper
                .eq("id", user.getId())
                .and(wr -> wr.eq("name", user.getName()));

        return  userMapper.selectOne(wrapper);

    }


    public List<User> selectList(User user) {

        QueryWrapper<User> wrapper = new QueryWrapper<User>();
        wrapper
                .eq("id", user.getId())
                .or(wr -> wr.eq("name", user.getName()));
        return userMapper.selectList(wrapper);
    }

    public Page<User> selectPage(int pageNo, int pageSize) {
        return userMapper.selectPage(
                new Page<User>(pageNo, pageSize),
                new QueryWrapper<User>(){{
                    gt("id", 1);
                }}
        );
    }
}